﻿using AutoMapper;
using CommonType;
using MediatR;
using S_Gridding.Api.Application.Commands.AssemType;
using S_Gridding.Domains.BasicData;
using S_Gridding.Infrastructure.Interface;

namespace S_Gridding.Api.Application.CommandsHanders.AssemType
{
    /// <summary>
    /// 中介者模式修改部件类型信息
    /// </summary>
    public class AssemTypeUpdateCommandHander : IRequestHandler<AssemTypeUpdateCommand, int>
    {
        private readonly IAssemTypeRepository _assemTypeRepository;  //部件类型表的底层仓储
        private readonly IMapper _mapper;  //AutoMapper

        public AssemTypeUpdateCommandHander(IAssemTypeRepository assemTypeRepository, IMapper mapper)
        {
            _assemTypeRepository = assemTypeRepository;
            _mapper = mapper;
        }

        public async Task<int> Handle(AssemTypeUpdateCommand request, CancellationToken cancellationToken)
        {
            var res = _mapper.Map<AssemTypeInfo>(request);
            return await _assemTypeRepository.UpdateAsync(res);
        }
    }
}
